package com.ebupt.migu.music.common.util;


import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

/**
 * @program: graphic
 * @description:
 * @author: zhanggk
 * @create: 2018-10-12 14:36
 **/
@Slf4j
public class DefaultVal {

    /**
     * String 转换 int
     * @param str string
     * @param defaultVal 默认值，str不是int类型，返回默认值
     * @return int
     */
    public static int strToInt(String str, int defaultVal){
        int val = defaultVal;
        if (!StringUtils.isBlank(str)) {
            try {
               val = Integer.parseInt(str);
            } catch (NumberFormatException e) {
                log.error("add message err", e);
            }
        }
        return val;
    }


}